
//#include <xcpux.h>
#include <stdio.h>
#include <stdint.h>

/*
不需要SET_REG_PARAM
重定义inst_name(name,idx,id)
*/
#define SET_REG_PARAM(...)

static int is_err = 0;
static int insn_proc(uint32_t *reg,const char*name,uint32_t insn,int idx,int id);
#define inst_name(name,idx,id) is_err=0; if(insn_proc(reg,name,insn,(idx),(id))) return;
#include "arm_case.h"

static const int p_base_v[] = {
1,3,5, //adc
9,13,15, 17,21, //add
23, //addr
25,27,29,   //and
41,43,45,   //bic
83,85,87,   //eor
205,207,209,    //mvn
217,219,221,    //orr
275,277,279,    //rsb
281,283,285,    //rsc
293,295,297,    //sbc
411,413,415,    //sub
417,419,        //sub rd,sp

};

static const int p_cmp_v[]= {
65,67,69,       //cmn
71,73,75,       //cmp
439,441,443,    //teq
445,447,449,    //tst
};

static const int p_shift_v[] = {
169,171,    //lsl
173,175,    //lsr
31,33,      //asr
269,271,    //ror
};

#ifndef proc_insn
#define proc_insn(n) fprintf(stdout,"%s\n",n)
#endif

#define A0 reg[xcpu_arg0 + 0]
#define A1 reg[xcpu_arg0 + 1]
#define A2 reg[xcpu_arg0 + 2]
#define A3 reg[xcpu_arg0 + 3]
#define A4 reg[xcpu_arg0 + 4]
#define A5 reg[xcpu_arg0 + 5]
#define A6 reg[xcpu_arg0 + 6]
#define A7 reg[xcpu_arg0 + 7]

typedef void (*emu_insn_t)(uint32_t*R,...);

static void UndefinedInstruction(uint32_t*R){

}

extern void adc_imm12(uint32_t*R,...);
extern void add_imm12(uint32_t*R,...);
extern void and_imm12(uint32_t*R,...);
extern void bic_imm12(uint32_t*R,...);
extern void eor_imm12(uint32_t*R,...);
extern void orr_imm12(uint32_t*R,...);
extern void rsb_imm12(uint32_t*R,...);
extern void rsc_imm12(uint32_t*R,...);
extern void sbc_imm12(uint32_t*R,...);
extern void sub_imm12(uint32_t*R,...);
extern void cmn_imm12(uint32_t*R,...);
extern void cmp_imm12(uint32_t*R,...);
extern void teq_imm12(uint32_t*R,...);
extern void tst_imm12(uint32_t*R,...);
extern void mvn_imm12(uint32_t*R,...);

#define DEF_FUNC(name) \
extern void name##_lsl2(uint32_t*R,...); \
extern void name##_lsr2(uint32_t*R,...); \
extern void name##_asr2(uint32_t*R,...); \
extern void name##_ror2(uint32_t*R,...); \
extern void name##_lsl2_S(uint32_t*R,...); \
extern void name##_lsr2_S(uint32_t*R,...); \
extern void name##_asr2_S(uint32_t*R,...); \
extern void name##_ror2_S(uint32_t*R,...); \
extern void name##_lsl1(uint32_t*R,...); \
extern void name##_lsr1(uint32_t*R,...); \
extern void name##_asr1(uint32_t*R,...); \
extern void name##_ror1(uint32_t*R,...); \
extern void name##_lsl1_S(uint32_t*R,...); \
extern void name##_lsr1_S(uint32_t*R,...); \
extern void name##_asr1_S(uint32_t*R,...); \
extern void name##_ror1_S(uint32_t*R,...); \
extern void name##_imm12(uint32_t*R,...); \
extern void name##_imm12_S(uint32_t*R,...); \
void name##_shift_reg(uint32_t*R,uint32_t insn){ \
    static const emu_insn_t insns[] = { \
        name##_lsl2, \
        name##_lsr2, \
        name##_asr2, \
        name##_ror2, \
        name##_lsl2_S, \
        name##_lsr2_S, \
        name##_asr2_S, \
        name##_ror2_S, \
    }; \
    int shift=(insn>>5)&3; \
    shift |= ((insn>>20)&1)<<2; \
    emu_insn_t ptr = insns[shift]; \
    return ptr(R,bit(insn,12,4),bit(insn,16,4),bit(insn,0,4),bit(insn,8,4)); \
} \
void name##_shift_imm(uint32_t*R,uint32_t insn){ \
    static const emu_insn_t insns[] = { \
        name##_lsl1, \
        name##_lsr1, \
        name##_asr1, \
        name##_ror1, \
        name##_lsl1_S, \
        name##_lsr1_S, \
        name##_asr1_S, \
        name##_ror1_S, \
    }; \
    int shift=(insn>>5)&3; \
    shift |= ((insn>>20)&1)<<2; \
    emu_insn_t ptr = insns[shift]; \
    return ptr(R,bit(insn,12,4),bit(insn,16,4),bit(insn,0,4),bit(insn,7,5)); \
} \
void _##name##_imm12(uint32_t*R,uint32_t insn){ \
    int imm12 = bit(insn,0,12); \
    int n = bit(insn,16,4); \
    int d = bit(insn,12,4); \
    if(bit(insn,20,1)) \
        return name##_imm12_S(R,d,n,imm12);     \
    return name##_imm12(R,d,n,imm12);    \
}


#define STRLDR_DEF_SHIFT(name,shift) \
extern void  name##1_##shift(uint32_t*R,...); \
extern void  name##2_##shift(uint32_t*R,...); \
extern void  name##3_##shift(uint32_t*R,...); \
extern void name##1s_##shift(uint32_t*R,...); \
extern void name##2s_##shift(uint32_t*R,...); \
extern void name##3s_##shift(uint32_t*R,...);

#define STRLDR_DEF_SHIFT_LIST(name,shift) \
    name##1s_##shift, \
    (emu_insn_t)UndefinedInstruction, \
    name##3s_##shift, \
    name##2s_##shift, \
    name##1_##shift, \
    (emu_insn_t)UndefinedInstruction, \
    name##3_##shift, \
    name##2_##shift, \




#define STRLDR_DEF(name) \
extern void name##1imm(uint32_t*R,...); \
extern void name##2imm(uint32_t*R,...); \
extern void name##3imm(uint32_t*R,...); \
extern void name##1simm(uint32_t*R,...); \
extern void name##2simm(uint32_t*R,...); \
extern void name##3simm(uint32_t*R,...); \
static void name(uint32_t*R,uint32_t insn){ \
    int t = bit(insn,12,4); \
    int n = bit(insn,16,4); \
    int32_t imm12 = bit(insn,0,12); \
    static const emu_insn_t insns[] = { \
        name##1simm, \
        (emu_insn_t)UndefinedInstruction, \
        name##3simm, \
        name##2simm, \
        name##1imm,  /*U=1,P=0,W=0*/ \
        (emu_insn_t)UndefinedInstruction, \
        name##3imm,  /*U=1,P=1,W=0*/ \
        name##2imm,  /*U=1,P=1,W=1*/ \
    }; \
    int idx = 0; \
    idx |= bit(insn,21,1)<<0; \
    idx |= bit(insn,24,1)<<1; \
    idx |= bit(insn,23,1)<<2; \
    return insns[idx](R,t,n,imm12); \
} \
STRLDR_DEF_SHIFT(name,lsl); \
STRLDR_DEF_SHIFT(name,lsr); \
STRLDR_DEF_SHIFT(name,asr); \
STRLDR_DEF_SHIFT(name,ror); \
static void name##_shift(uint32_t*R,uint32_t insn){ \
    int t=bit(insn,12,4); \
    int n=bit(insn,16,4); \
    int m=bit(insn,0,4); \
    int imm = bit(insn,7,5); \
    static const emu_insn_t insns[] = { \
        STRLDR_DEF_SHIFT_LIST(name,lsl) \
        STRLDR_DEF_SHIFT_LIST(name,lsr) \
        STRLDR_DEF_SHIFT_LIST(name,asr) \
        STRLDR_DEF_SHIFT_LIST(name,ror) \
    }; \
    int idx = 0; \
    idx |= bit(insn,21,1)<<0; \
    idx |= bit(insn,24,1)<<1; \
    idx |= bit(insn,23,1)<<2; \
    idx |= bit(insn,5,2)<<3; \
    return insns[idx](R,t,n,m,imm); \
}

#define STM_LDM_DEF(name) \
extern void name(uint32_t*R,...); \
extern void name##ib(uint32_t*R,...); \
extern void name##da(uint32_t*R,...); \
extern void name##db(uint32_t*R,...); \
extern void name##_w(uint32_t*R,...); \
extern void name##ib_w(uint32_t*R,...); \
extern void name##da_w(uint32_t*R,...); \
extern void name##db_w(uint32_t*R,...); \
static void __##name(uint32_t*R,uint32_t insn){ \
    static const emu_insn_t insns[] = { \
        name##da, \
        name##db, \
        name, \
        name##ib, \
        name##da_w, \
        name##db_w, \
        name##_w, \
        name##ib_w, \
    }; \
    int n = bit(insn,16,4); \
    int list = bit(insn,0,16); \
    int idx = 0; \
    idx |= bit(insn,24,1)<<0; /*B*/ \
    idx |= bit(insn,23,1)<<1; /*I*/ \
    idx |= bit(insn,21,1)<<2; \
    return insns[idx](R,n,list); \
}

#define STRH_LDRH_DEF(name) \
extern void name##1_reg (uint32_t*R,...); \
extern void name##2_reg (uint32_t*R,...); \
extern void name##3_reg (uint32_t*R,...); \
extern void name##1s_reg(uint32_t*R,...); \
extern void name##2s_reg(uint32_t*R,...); \
extern void name##3s_reg(uint32_t*R,...); \
extern void name##1_imm(uint32_t*R,...); \
extern void name##2_imm(uint32_t*R,...); \
extern void name##3_imm(uint32_t*R,...); \
extern void name##1s_imm(uint32_t*R,...); \
extern void name##2s_imm(uint32_t*R,...); \
extern void name##3s_imm(uint32_t*R,...); \
static void __##name##_reg(uint32_t*R,uint32_t insn){ \
    int t = bit(insn,12,4); \
    int n = bit(insn,16,4); \
    int m = bit(insn,0,4); \
    static const emu_insn_t insns[] = { \
        name##1s_reg, \
        (emu_insn_t)UndefinedInstruction, \
        name##3s_reg, \
        name##2s_reg, \
        name##1_reg, \
        (emu_insn_t)UndefinedInstruction, \
        name##3_reg, \
        name##2_reg, \
    }; \
    int idx = 0; \
    idx |= bit(insn,21,1)<<0; \
    idx |= bit(insn,24,1)<<1; \
    idx |= bit(insn,23,1)<<2; \
    return insns[idx](R,t,n,m); \
} \
static void __##name##_imm(uint32_t*R,uint32_t insn){ \
    int t = bit(insn,12,4); \
    int n = bit(insn,16,4); \
    int imml = bit(insn,0,4); \
    int immh = bit(insn,8,4); \
    static const emu_insn_t insns[] = { \
        name##1s_imm, \
        (emu_insn_t)UndefinedInstruction, \
        name##3s_imm, \
        name##2s_imm, \
        name##1_imm, \
        (emu_insn_t)UndefinedInstruction, \
        name##3_imm, \
        name##2_imm, \
    }; \
    int idx = 0; \
    idx |= bit(insn,21,1)<<0; \
    idx |= bit(insn,24,1)<<1; \
    idx |= bit(insn,23,1)<<2; \
    return insns[idx](R,t,n,immh,imml); \
}

extern void mov_lsl1(uint32_t*R,...);
extern void mov_lsr1(uint32_t*R,...);
extern void mov_asr1(uint32_t*R,...);
extern void mov_ror1(uint32_t*R,...);
extern void mov_lsl1_S(uint32_t*R,...);
extern void mov_lsr1_S(uint32_t*R,...);
extern void mov_asr1_S(uint32_t*R,...);
extern void mov_ror1_S(uint32_t*R,...);
extern void mov_lsl2(uint32_t*R,...);
extern void mov_lsr2(uint32_t*R,...);
extern void mov_asr2(uint32_t*R,...);
extern void mov_ror2(uint32_t*R,...);
extern void mov_lsl2_S(uint32_t*R,...);
extern void mov_lsr2_S(uint32_t*R,...);
extern void mov_asr2_S(uint32_t*R,...);
extern void mov_ror2_S(uint32_t*R,...);
static void _mov1(uint32_t*R,uint32_t insn){
    static const emu_insn_t insns[] = {
        mov_lsl1,
        mov_lsr1,
        mov_asr1,
        mov_ror1,
        mov_lsl1_S,
        mov_lsr1_S,
        mov_asr1_S,
        mov_ror1_S,
    };
    int n = 0;
    int d = bit(insn,12,4);
    int m = bit(insn,0,4);
    int imm = bit(insn,7,5);
    int idx = 0;
    idx |= bit(insn,5,2);
    idx |= bit(insn,20,1)<<2;
    return insns[idx](R,d,n,m,imm);
}
static void _mov2(uint32_t*R,uint32_t insn){
    static const emu_insn_t insns[] = {
        mov_lsl2,
        mov_lsr2,
        mov_asr2,
        mov_ror2,
        mov_lsl2_S,
        mov_lsr2_S,
        mov_asr2_S,
        mov_ror2_S,
    };
    int n = 0;
    int d = bit(insn,12,4);
    int m = bit(insn,0,4);
    int s = bit(insn,8,4);
    int idx = 0;
    idx |= bit(insn,5,2);
    idx |= bit(insn,20,1)<<2;
    return insns[idx](R,d,n,m,s);
}

void b(uint32_t*R,...);
void blx_imm(uint32_t*R,...);
void bl(uint32_t*R,...);
extern void bx(uint32_t*R,...);
extern void bkpt(uint32_t*R,...);
extern void mla(uint32_t*R,...);
extern void mlaS(uint32_t*R,...);
extern void mls(uint32_t*R,...);
extern void mov_imm12(uint32_t*R,...);
extern void mov_imm12_S(uint32_t*R,...);
extern void mrs(uint32_t*R,...);
extern void mrs_spsr(uint32_t*R,...);
extern void msr_imm(uint32_t*R,...);
extern void msr(uint32_t*R,...);
extern void msr_spsr(uint32_t*R,...);
extern void msr_imm_spsr(uint32_t*R,...);
extern void mulS(uint32_t*R,...);
extern void mul(uint32_t*R,...);
extern void pkh_asr(uint32_t*R,...);
extern void pkh_lsl(uint32_t*R,...);
extern void rbit(uint32_t*R,...);
extern void rev(uint32_t*R,...);
extern void rev16(uint32_t*R,...);
extern void revsh(uint32_t*R,...);
extern void smlalS(uint32_t*R,...);
extern void smlal(uint32_t*R,...);
extern void smullS(uint32_t*R,...);
extern void smull(uint32_t*R,...);
extern void umlals(uint32_t*R,...);
extern void umlal(uint32_t*R,...);
extern void umulls(uint32_t*R,...);
extern void umull(uint32_t*R,...);
extern void svc(uint32_t*R,...);
extern void swp(uint32_t*R,...);
extern void swpb(uint32_t*R,...);

void _bl(uint32_t*R,uint32_t insn){
    if(bit(insn,28,4)==0xf){
        return blx_imm(R,insn);
    }
    else{
        return bl(R,insn);
    }
}
static void _bx(uint32_t*R,uint32_t insn){
    return bx(R,insn&0xf);
}

static void _bkpt(uint32_t*R,uint32_t insn){
    return bkpt(R,bit(insn,8,12),bit(insn,0,4));
}

static void _mla(uint32_t*R,uint32_t insn){
    int d = bit(insn,16,4),a=bit(insn,12,4),m=bit(insn,8,4),n=bit(insn,0,4);
    if(bit(insn,20,1))
        return mlaS(R,d,n,m,a);
    return mla(R,d,n,m,a);
}
static void _mls(uint32_t*R,uint32_t insn){
    int d = bit(insn,16,4),a=bit(insn,12,4),m=bit(insn,8,4),n=bit(insn,0,4);
    return mls(R,d,n,m,a);
}
static void _mov(uint32_t*R,uint32_t insn){
    if(bit(insn,20,1))
        return mov_imm12_S(R,bit(insn,12,4),0,bit(insn,0,12));
    return mov_imm12(R,bit(insn,12,4),0,bit(insn,0,12));
}

static void _mrs(uint32_t*R,uint32_t insn){
    if(bit(insn,22,1)){
        return mrs_spsr(R,bit(insn,12,4));
    }
    else{
        return mrs(R,bit(insn,12,4));
    }
}
static void _msr_imm(uint32_t*R,uint32_t insn){
    if(bit(insn,22,1))
        return msr_imm_spsr(R,bit(insn,16,4),bit(insn,0,12));
    return msr_imm(R,bit(insn,0,12));
}
static void _msr_reg(uint32_t*R,uint32_t insn){
    if(bit(insn,22,1))
        return msr_spsr(R,bit(insn,16,4),bit(insn,0,4));
    return msr(R,bit(insn,0,4));
}

static void _mul(uint32_t*R,uint32_t insn){
    int d = bit(insn,16,4);
    int m = bit(insn,8,4);
    int n = bit(insn,0,4);
    if(bit(insn,20,1))
        return mulS(R,d,n,m);
    return mul(R,d,n,m);
}

extern void nop(uint32_t*R,...);
static void _pkh(uint32_t*R,uint32_t insn){
    int d = bit(insn,12,4),n=bit(insn,16,4),m=bit(insn,0,4),shift_n=bit(insn,7,5);
    if(bit(insn,6,1)){
        return pkh_asr(R,d,n,m,shift_n);
    }
    return pkh_lsl(R,d,n,m,shift_n);
}

static void _pld(uint32_t*R,uint32_t insn){
    int n = bit(insn,16,4),imm = bit(insn,0,12);
}

static void _rbit(uint32_t*R,uint32_t insn){
    int d = bit(insn,12,4),m=bit(insn,0,4);
    return rbit(R,d,m);
}

static void _rev(uint32_t*R,uint32_t insn){
    int d=(insn,12,4),m=bit(insn,0,4);
    return rev(R,d,m);
}
static void _rev16(uint32_t*R,uint32_t insn){
    int d=(insn,12,4),m=bit(insn,0,4);
    return rev(R,d,m);
}

static void _revsh(uint32_t*R,uint32_t insn){
    int d=(insn,12,4),m=bit(insn,0,4);
    return rev(R,d,m);
}

static void _smlal(uint32_t*R,uint32_t insn){
    int dlo=bit(insn,12,4),dhi=bit(insn,16,4),n=bit(insn,0,4),m=bit(insn,8,4);
    if(bit(insn,20,1))
        return smlalS(R,dlo,dhi,n,m);
    return smlal(R,dlo,dhi,n,m);
}

static void _smull(uint32_t*R,uint32_t insn){
    int dlo=bit(insn,12,4),dhi=bit(insn,16,4),n=bit(insn,0,4),m=bit(insn,8,4);
    if(bit(insn,20,1))
        return smullS(R,dlo,dhi,n,m);
    return smull(R,dlo,dhi,n,m);
}

static void _umlal(uint32_t*R,uint32_t insn){
    int dlo=bit(insn,12,4),dhi=bit(insn,16,4),n=bit(insn,0,4),m=bit(insn,8,4);
    if(bit(insn,20,1))
        return umlals(R,dlo,dhi,n,m);
    return umlal(R,dlo,dhi,n,m);
}

static void _umull(uint32_t*R,uint32_t insn){
    int dlo=bit(insn,12,4),dhi=bit(insn,16,4),n=bit(insn,0,4),m=bit(insn,8,4);
    if(bit(insn,20,1))
        return umulls(R,dlo,dhi,n,m);
    return umull(R,dlo,dhi,n,m);
}

static void _svc(uint32_t*R,uint32_t insn){
    return svc(R,bit(insn,0,24));
}

static void _swp(uint32_t*R,uint32_t insn){
    int t=bit(insn,12,4),n=bit(insn,16,4),t2=bit(insn,0,4);
    if(bit(insn,22,1)){
        return swpb(R,t,t2,n);
    }
    return swp(R,t,t2,n);
}

DEF_FUNC(adc);
DEF_FUNC(add);
DEF_FUNC(and);
DEF_FUNC(bic);
DEF_FUNC(eor);
DEF_FUNC(orr);
DEF_FUNC(rsb);
DEF_FUNC(rsc);
DEF_FUNC(sbc);
DEF_FUNC(sub);
DEF_FUNC(mvn);

DEF_FUNC(tst);
DEF_FUNC(teq);
DEF_FUNC(cmp);
DEF_FUNC(cmn);

STRLDR_DEF(strb);
STRLDR_DEF(str);
STRLDR_DEF(ldrb);
STRLDR_DEF(ldr);

STM_LDM_DEF(stm);
STM_LDM_DEF(ldm);

STRH_LDRH_DEF(ldrh);
STRH_LDRH_DEF(ldrsh);
STRH_LDRH_DEF(strh);
STRH_LDRH_DEF(ldrsb);
STRH_LDRH_DEF(strd);
STRH_LDRH_DEF(ldrd);

// const emu_insn_t base_insn[900] = {

// };

const emu_insn_t insn_all[900] = {
[1] =(emu_insn_t)  _adc_imm12,
[9] =(emu_insn_t)  _add_imm12,
[25] =(emu_insn_t) _and_imm12,
[41]  =(emu_insn_t)_bic_imm12,
[65]  =(emu_insn_t)_cmn_imm12,
[71]  =(emu_insn_t)_cmp_imm12,
[83]  =(emu_insn_t)_eor_imm12,
[217] =(emu_insn_t)_orr_imm12,
[275] =(emu_insn_t)_rsb_imm12,
[281] =(emu_insn_t)_rsc_imm12,
[293] =(emu_insn_t)_sbc_imm12,
[411] =(emu_insn_t)_sub_imm12,
[439] =(emu_insn_t)_teq_imm12,
[445] =(emu_insn_t)_tst_imm12,
[205] =(emu_insn_t)_mvn_imm12,

[5] =(emu_insn_t)  adc_shift_reg,
[15] =(emu_insn_t) add_shift_reg,
[29] =(emu_insn_t) and_shift_reg,
[45]  =(emu_insn_t)bic_shift_reg,
[69]  =(emu_insn_t)cmn_shift_reg,
[75]  =(emu_insn_t)cmp_shift_reg,
[87]  =(emu_insn_t)eor_shift_reg,
[221] =(emu_insn_t)orr_shift_reg,
[279] =(emu_insn_t)rsb_shift_reg,
[285] =(emu_insn_t)rsc_shift_reg,
[297] =(emu_insn_t)sbc_shift_reg,
[415] =(emu_insn_t)sub_shift_reg,
[443] =(emu_insn_t)teq_shift_reg,
[449] =(emu_insn_t)tst_shift_reg,
[3] =(emu_insn_t)  adc_shift_imm,
[13] =(emu_insn_t) add_shift_imm,
[27] =(emu_insn_t) and_shift_imm,
[43]  =(emu_insn_t)bic_shift_imm,
[67]  =(emu_insn_t)cmn_shift_imm,
[73]  =(emu_insn_t)cmp_shift_imm,
[85]  =(emu_insn_t)eor_shift_imm,
[219] =(emu_insn_t)orr_shift_imm,
[277] =(emu_insn_t)rsb_shift_imm,
[283] =(emu_insn_t)rsc_shift_imm,
[295] =(emu_insn_t)sbc_shift_imm,
[413] =(emu_insn_t)sub_shift_imm,
[441] =(emu_insn_t)teq_shift_imm,
[447] =(emu_insn_t)tst_shift_imm,
[207] =(emu_insn_t)mvn_shift_imm,
[209] =(emu_insn_t)mvn_shift_reg,

[109] =(emu_insn_t)ldr,
[115] =(emu_insn_t)ldr_shift,
[119] =(emu_insn_t)ldrb,
[123] =(emu_insn_t)ldrb_shift,
[375] =(emu_insn_t)str,
[377] =(emu_insn_t)str_shift,
[381] =(emu_insn_t)strb,
[383] =(emu_insn_t)strb_shift,

[99]  =(emu_insn_t) __ldm,
[101] =(emu_insn_t) __ldm,
[103] =(emu_insn_t) __ldm,
[105] =(emu_insn_t) __ldm,
[365] =(emu_insn_t) __stm,
[367] =(emu_insn_t) __stm,
[369] =(emu_insn_t) __stm,
[371] =(emu_insn_t) __stm,

[127] =(emu_insn_t) __ldrd_imm,
[131] =(emu_insn_t) __ldrd_reg,
[143] =(emu_insn_t) __ldrh_imm,
[147] =(emu_insn_t) __ldrh_reg,
[151] =(emu_insn_t) __ldrsb_imm,
[155] =(emu_insn_t) __ldrsb_reg,
[159] =(emu_insn_t) __ldrsh_imm,
[163] =(emu_insn_t) __ldrsh_reg,

[387] =(emu_insn_t) __strd_imm,
[389] =(emu_insn_t) __strd_reg,
[401] =(emu_insn_t) __strh_imm,
[403] =(emu_insn_t) __strh_reg,

[31] =(emu_insn_t)  _mov1, //ASR
[33] =(emu_insn_t)  _mov2, //ASR
[169] =(emu_insn_t) _mov1, //LSL
[171] =(emu_insn_t) _mov2, //LSL
[173] =(emu_insn_t) _mov1, //LSR
[175] =(emu_insn_t) _mov2, //LSR
[269] =(emu_insn_t) _mov1, //ROR
[271] =(emu_insn_t) _mov2, //ROR

[35] =(emu_insn_t) b,
[49] =(emu_insn_t) _bl,

[53] =(emu_insn_t) _bx,
[47] =(emu_insn_t) _bkpt,

[181] =(emu_insn_t) _mla,
[183] =(emu_insn_t) _mls,
[185] =(emu_insn_t) _mov,
[189] =(emu_insn_t) _mov1,
[197] =(emu_insn_t) _mrs,
[199] =(emu_insn_t) _msr_imm,
[201] =(emu_insn_t) _msr_reg,

[203] =(emu_insn_t) _mul,
[211] =(emu_insn_t) nop,
[223] =(emu_insn_t) _pkh,

[237] =(emu_insn_t) __ldm, //pop
[239] =(emu_insn_t) __stm, //push

[261] =(emu_insn_t) _rbit,
[263] =(emu_insn_t) _rev,
[265] =(emu_insn_t) _rev16,
[269] =(emu_insn_t) _revsh,

[325] =(emu_insn_t) _smlal,
[347] =(emu_insn_t) _smull,
[421] =(emu_insn_t) _svc,
[423] =(emu_insn_t) _swp,
[477] =(emu_insn_t) _umlal,
[479] =(emu_insn_t) _umull,

};

#include <stdio.h>
static int insn_proc(uint32_t *reg,const char*name,uint32_t insn,int idx,int id){
    char buf[BUFSIZ];
    int pos = 0;
    if(!strcmp(name,"PUSH")){
        pos = 1;
    }
    if(insn_all[id]){
        insn_all[id](reg,insn);
    }
    else{
        fprintf(stderr,"err insn:%08X,%08X",reg[15],insn);
        return -1;
    }
    return 0;
}

int arm_exec(uint32_t *reg,uint32_t insn){
    is_err = 1;
    inst_exec(reg,insn);
}

